import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

/* Layout */
import Layout from '@/layout';

/**
 * Note: sub-menu only appear when route children.length >= 1
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  // 告警工具-健康码
  {
    path: '/gjgj',
    component: Layout,
    redirect: '/jkm',
    name: 'gjgj',
    meta: {
      title: '告警工具',
      icon: 'el-icon-s-platform'
    },
    children: [
      {
        path: '/jkm',
        name: 'jkm',
        component: () => import('@/views/gjgj/child/jkm'),
        meta: { title: '健康码', icon: 'el-icon-s-platform' }
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    name: 'index',
    meta: {
      title: '首页',
      icon: 'el-icon-s-platform'
    },
    children: [
      {
        path: '/index',
        name: '首页',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '首页', icon: 'el-icon-s-platform' }
      }
    ]
  },
  {
    path: '/tools',
    name: 'tools',
    component: Layout,
    meta: {
      title: '运维工具',
      icon: 'el-icon-user-solid'
    },
    children: [{
      path: 'change',
      redirect: '/tools/change/recordtools',
      component: () =>
        import('@/views/tools/index'), // Parent router-view
      name: 'changetools',
      meta: {
        title: '交换机封堵工具'
      },
      children: [{
        path: 'fd',
        component: () => import('@/views/tools/child/edit'),

        name: 'fdtools',
        meta: {
          title: '封堵工具'
        }
      },
      {
        path: 'recordtools',
        component: () => import('@/views/tools/child/index'),
        name: 'recordtools',
        meta: {
          title: '封堵操作记录'
        }
      },

      ]
    }, {
      path: 'firewallOne',
      redirect: '/tools/firewallOne/recordtools',
      component: () =>
        import('@/views/tools/index'), // Parent router-view
      name: 'firewallOnetools',
      meta: {
        title: '防火墙1封堵工具'
      },
      children: [{
        path: 'fd',
        component: () => import('@/views/tools/firewallOne/edit'),
        name: 'fdtools',
        meta: {
          title: '防火墙1-封堵工具'
        }
      },
      {
        path: 'recordtools',
        component: () => import('@/views/tools/firewallOne/index'),
        // component: resolve =>
        //   require([
        //     '@/views/tools/child/index'
        //   ], resolve),
        name: 'recordtools',
        meta: {
          title: '防火墙1-封堵操作记录'
        }
      },
      ]
    },
    {
      path: 'firewallTwo',
      redirect: '/tools/firewallTwo/recordtools',
      component: () =>
        import('@/views/tools/index'), // Parent router-view
      name: 'firewallOnetools',
      meta: {
        title: '防火墙2封堵工具'
      },
      children: [{
        path: 'fd',
        component: () => import('@/views/tools/firewallTwo/edit'),
        name: 'fdtools',
        meta: {
          title: '防火墙2-封堵工具'
        }
      },
      {
        path: 'recordtools',
        component: () => import('@/views/tools/firewallTwo/index'),
        // component: resolve =>
        //   require([
        //     '@/views/tools/child/index'
        //   ], resolve),
        name: 'recordtools',
        meta: {
          title: '防火墙2-封堵操作记录'
        }
      },
      ]
    },
    {
      path: 'blackName',
      redirect: '/tools/blackName/display',
      component: () =>
        import('@/views/tools/index'), // Parent router-view
      name: 'blackName',
      meta: {
        title: '白名单'
      },
      children: [{
        path: 'display',
        component: () => import('@/views/tools/blackName/edit'),
        name: 'display',
        meta: {
          title: '白名单展示'
        }
      },
      ]
    },
    {
      path: 'fireWallRealm',
      redirect: '/tools/fireWallRealm/display',
      component: () =>
        import('@/views/tools/index'), // Parent router-view
      name: 'blackName',
      meta: {
        title: '防火墙域名封堵'
      },
      children: [{
        path: 'display',
        component: () => import('@/views/tools/fireWallRealm/edit'),
        name: 'display',
        meta: {
          title: '防火墙域名封堵'
        }
      },
      ]
    },
    {
      path: 'fenShenScreen',
      redirect: '/tools/fenShenScreen/fenShen',
      component: () =>
        import('@/views/tools/index'), // Parent router-view
      name: 'fenShenScreen',
      meta: {
        title: '封神大屏'
      },
      children: [{
        path: 'fenShen',
        component: () => import('@/views/tools/fenShenScreen'),
        name: 'fenShen',
        meta: {
          title: '封神大屏'
        }
      },
      ]
    },
    {
      path: 'fenShenScreenTotal',
      redirect: '/tools/fenShenScreen/fenShenTotal',
      component: () =>
        import('@/views/tools/index'), // Parent router-view
      name: 'fenShenScreen',
      meta: {
        title: '封神记录查询界面'
      },
      children: [{
        path: 'fenShenTotal',
        component: () => import('@/views/tools/fenShenScreenTotal'),
        name: 'fenShenTotal',
        meta: {
          title: '封神记录查询界面'
        }
      },
      ]
    },
    ]
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  { path: '*', redirect: '/404', hidden: true }

];
// 客户人员路由
export const asyncRouterMap = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  //登录页
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    name: '首页',
    meta: {
      title: '首页',
      icon: 'el-icon-s-platform'
    },
    children: [
      {
        path: '/index',
        name: '首页',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '首页', icon: 'el-icon-s-platform' }
      }
    ]
  },


  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  { path: '*', redirect: '/404', hidden: true },

]
// admin时路由   目前的路由权限是在这里配置
export const awaitRouterMap = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  //登录页
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    name: '首页',
    meta: {
      title: '首页',
      icon: 'el-icon-s-platform'
    },
    children: [
      {
        path: '/index',
        name: '首页',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '首页', icon: 'el-icon-s-platform' }
      }
    ]
  },
  // 权限路由
  {
    path: '/tools',
    name: 'tools',
    component: Layout,
    meta: {
      title: '运维工具',
      icon: 'el-icon-user-solid'
    },
    children: [{
      path: 'change',
      redirect: '/tools/change/recordtools',
      component: () =>
        import('@/views/tools/index'), // Parent router-view
      name: 'changetools',
      meta: {
        title: '交换机封堵工具'
      },
      children: [{
        path: 'fd',
        component: () => import('@/views/tools/child/edit'),
        name: 'fdtools',
        meta: {
          title: '封堵工具'
        }
      },
      {
        path: 'recordtools',
        component: () => import('@/views/tools/child/index'),
        // component: resolve =>
        //   require([
        //     '@/views/tools/child/index'
        //   ], resolve),
        name: 'recordtools',
        meta: {
          title: '封堵操作记录'
        }
      },

      ]
    }, {
      path: 'firewallOne',
      redirect: '/tools/firewallOne/recordtools',
      component: () =>
        import('@/views/tools/index'), // Parent router-view
      name: 'firewallOnetools',
      meta: {
        title: '防火墙1封堵工具'
      },
      children: [{
        path: 'fd',
        component: () => import('@/views/tools/firewallOne/edit'),
        name: 'fdtools',
        meta: {
          title: '防火墙1-封堵工具'
        }
      },
      {
        path: 'recordtools',
        component: () => import('@/views/tools/firewallOne/index'),
        // component: resolve =>
        //   require([
        //     '@/views/tools/child/index'
        //   ], resolve),
        name: 'recordtools',
        meta: {
          title: '防火墙1-封堵操作记录'
        }
      }
      ]
    },
    {
      path: 'firewallTwo',
      redirect: '/tools/firewallTwo/recordtools',
      component: () =>
        import('@/views/tools/index'), // Parent router-view
      name: 'firewallOnetools',
      meta: {
        title: '防火墙2封堵工具'
      },
      children: [{
        path: 'fd',
        component: () => import('@/views/tools/firewallTwo/edit'),
        name: 'fdtools',
        meta: {
          title: '防火墙2-封堵工具'
        }
      },
      {
        path: 'recordtools',
        component: () => import('@/views/tools/firewallTwo/index'),
        // component: resolve =>
        //   require([
        //     '@/views/tools/child/index'
        //   ], resolve),
        name: 'recordtools',
        meta: {
          title: '防火墙2-封堵操作记录'
        }
      },
      ]
    },
    {
      path: 'blackName',
      redirect: '/tools/blackName/display',
      component: () =>
        import('@/views/tools/index'), // Parent router-view
      name: 'blackName',
      meta: {
        title: '白名单'
      },
      children: [{
        path: 'display',
        component: () => import('@/views/tools/blackName/edit'),
        name: 'display',
        meta: {
          title: '白名单展示'
        }
      },

      ]
    },
    {
      path: 'fireWallRealm',
      redirect: '/tools/fireWallRealm/display',
      component: () =>
        import('@/views/tools/index'), // Parent router-view
      name: 'blackName',
      meta: {
        title: '防火墙域名封堵'
      },
      children: [{
        path: 'display',
        component: () => import('@/views/tools/fireWallRealm/edit'),
        name: 'display',
        meta: {
          title: '防火墙域名封堵'
        }
      },
      ]
    },
    {
      path: 'fenShenScreen',
      redirect: '/tools/fenShenScreen/fenShen',
      component: () =>
        import('@/views/tools/index'), // Parent router-view
      name: 'fenShenScreen',
      meta: {
        title: '封神大屏'
      },
      children: [{
        path: 'fenShen',
        component: () => import('@/views/tools/fenShenScreen'),
        name: 'fenShen',
        meta: {
          title: '封神大屏'
        }
      },
      ]
    },
    {
      path: 'fenShenScreenTotal',
      redirect: '/tools/fenShenScreen/fenShenTotal',
      component: () =>
        import('@/views/tools/index'), // Parent router-view
      name: 'fenShenScreen',
      meta: {
        title: '封神记录查询界面'
      },
      children: [{
        path: 'fenShenTotal',
        component: () => import('@/views/tools/fenShenScreenTotal'),
        name: 'fenShenTotal',
        meta: {
          title: '封神记录查询界面'
        }
      },
      ]
    },
    ]
  },
  // 告警工具-健康码
  {
    path: '/gjgj',
    component: Layout,
    redirect: '/jkm',
    name: 'gjgj',
    meta: {
      title: '告警工具',
      icon: 'el-icon-s-platform'
    },
    children: [
      {
        path: '/jkm',
        name: 'jkm',
        component: () => import('@/views/gjgj/child/jkm'),
        meta: { title: '健康码', icon: 'el-icon-s-platform' }
      }
    ]
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  { path: '*', redirect: '/404', hidden: true },

]

const createRouter = () =>
  new Router({
    mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
    async: asyncRouterMap,
    await: awaitRouterMap,
  });

const router = createRouter();

export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
